{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "2e3baab0",
   "metadata": {
    "papermill": {
     "duration": 0.004486,
     "end_time": "2025-02-15T12:07:25.100196",
     "exception": false,
     "start_time": "2025-02-15T12:07:25.095710",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "**This notebook is an exercise in the [Introduction to Machine Learning](https://www.kaggle.com/learn/intro-to-machine-learning) course.  You can reference the tutorial at [this link](https://www.kaggle.com/dansbecker/model-validation).**\n",
    "\n",
    "---\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c6e13af2",
   "metadata": {
    "papermill": {
     "duration": 0.003344,
     "end_time": "2025-02-15T12:07:25.107430",
     "exception": false,
     "start_time": "2025-02-15T12:07:25.104086",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Recap\n",
    "You've built a model. In this exercise you will test how good your model is.\n",
    "\n",
    "Run the cell below to set up your coding environment where the previous exercise left off."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2a5cfaf7",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T12:07:25.116108Z",
     "iopub.status.busy": "2025-02-15T12:07:25.115715Z",
     "iopub.status.idle": "2025-02-15T12:07:28.256195Z",
     "shell.execute_reply": "2025-02-15T12:07:28.254749Z"
    },
    "papermill": {
     "duration": 3.147428,
     "end_time": "2025-02-15T12:07:28.258553",
     "exception": false,
     "start_time": "2025-02-15T12:07:25.111125",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "First in-sample predictions: [208500. 181500. 223500. 140000. 250000.]\n",
      "Actual target values for those homes: [208500, 181500, 223500, 140000, 250000]\n",
      "Setup Complete\n"
     ]
    }
   ],
   "source": [
    "# Code you have previously used to load data\n",
    "import pandas as pd\n",
    "from sklearn.tree import DecisionTreeRegressor\n",
    "\n",
    "# Path of the file to read\n",
    "iowa_file_path = '../input/home-data-for-ml-course/train.csv'\n",
    "\n",
    "home_data = pd.read_csv(iowa_file_path)\n",
    "y = home_data.SalePrice\n",
    "feature_columns = ['LotArea', 'YearBuilt', '1stFlrSF', '2ndFlrSF', 'FullBath', 'BedroomAbvGr', 'TotRmsAbvGrd']\n",
    "X = home_data[feature_columns]\n",
    "\n",
    "# Specify Model\n",
    "iowa_model = DecisionTreeRegressor()\n",
    "# Fit Model\n",
    "iowa_model.fit(X, y)\n",
    "\n",
    "print(\"First in-sample predictions:\", iowa_model.predict(X.head()))\n",
    "print(\"Actual target values for those homes:\", y.head().tolist())\n",
    "\n",
    "# Set up code checking\n",
    "from learntools.core import binder\n",
    "binder.bind(globals())\n",
    "from learntools.machine_learning.ex4 import *\n",
    "print(\"Setup Complete\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "12f52161",
   "metadata": {
    "papermill": {
     "duration": 0.004,
     "end_time": "2025-02-15T12:07:28.267126",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.263126",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "# Exercises\n",
    "\n",
    "## Step 1: Split Your Data\n",
    "Use the `train_test_split` function to split up your data.\n",
    "\n",
    "Give it the argument `random_state=1` so the `check` functions know what to expect when verifying your code.\n",
    "\n",
    "Recall, your features are loaded in the DataFrame **X** and your target is loaded in **y**.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "132f5c5b",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T12:07:28.277700Z",
     "iopub.status.busy": "2025-02-15T12:07:28.277263Z",
     "iopub.status.idle": "2025-02-15T12:07:28.293658Z",
     "shell.execute_reply": "2025-02-15T12:07:28.292558Z"
    },
    "papermill": {
     "duration": 0.023939,
     "end_time": "2025-02-15T12:07:28.295601",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.271662",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 2, \"questionId\": \"1_SplitData\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc33\">Correct</span>"
      ],
      "text/plain": [
       "Correct"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Import the train_test_split function and uncomment\n",
    "# from _ import _\n",
    "from sklearn.model_selection import train_test_split\n",
    "\n",
    "# fill in and uncomment\n",
    "# train_X, val_X, train_y, val_y = ____\n",
    "train_X, val_X, train_y, val_y = train_test_split(X,y,random_state = 1)\n",
    "\n",
    "\n",
    "# Check your answer\n",
    "step_1.check()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "41b4e89a",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T12:07:28.306005Z",
     "iopub.status.busy": "2025-02-15T12:07:28.305602Z",
     "iopub.status.idle": "2025-02-15T12:07:28.316924Z",
     "shell.execute_reply": "2025-02-15T12:07:28.316009Z"
    },
    "papermill": {
     "duration": 0.018578,
     "end_time": "2025-02-15T12:07:28.318764",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.300186",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 2, \"questionType\": 2, \"questionId\": \"1_SplitData\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#3366cc\">Hint:</span> The function you need to import is part of sklearn. When calling the function, the arguments are X and y. Ensure you set the random_state to 1."
      ],
      "text/plain": [
       "Hint: The function you need to import is part of sklearn. When calling the function, the arguments are X and y. Ensure you set the random_state to 1."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 3, \"questionType\": 2, \"questionId\": \"1_SplitData\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc99\">Solution:</span> \n",
       "```python\n",
       "from sklearn.model_selection import train_test_split\n",
       "train_X, val_X, train_y, val_y = train_test_split(X, y, random_state=1)\n",
       "```"
      ],
      "text/plain": [
       "Solution: \n",
       "```python\n",
       "from sklearn.model_selection import train_test_split\n",
       "train_X, val_X, train_y, val_y = train_test_split(X, y, random_state=1)\n",
       "```"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# The lines below will show you a hint or the solution.\n",
    "step_1.hint() \n",
    "step_1.solution()\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5120f993",
   "metadata": {
    "papermill": {
     "duration": 0.004503,
     "end_time": "2025-02-15T12:07:28.328166",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.323663",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Step 2: Specify and Fit the Model\n",
    "\n",
    "Create a `DecisionTreeRegressor` model and fit it to the relevant data.\n",
    "Set `random_state` to 1 again when creating the model."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0cc3069d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T12:07:28.339015Z",
     "iopub.status.busy": "2025-02-15T12:07:28.338564Z",
     "iopub.status.idle": "2025-02-15T12:07:28.365193Z",
     "shell.execute_reply": "2025-02-15T12:07:28.364158Z"
    },
    "papermill": {
     "duration": 0.034133,
     "end_time": "2025-02-15T12:07:28.367092",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.332959",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[186500. 184000. 130000.  92000. 164500. 220000. 335000. 144152. 215000.\n",
      " 262000.]\n",
      "[186500. 184000. 130000.  92000. 164500. 220000. 335000. 144152. 215000.\n",
      " 262000.]\n"
     ]
    },
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 2, \"questionId\": \"2_FitModelWithTrain\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc33\">Correct</span>"
      ],
      "text/plain": [
       "Correct"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# You imported DecisionTreeRegressor in your last exercise\n",
    "# and that code has been copied to the setup code above. So, no need to\n",
    "# import it again\n",
    "\n",
    "# Specify the model\n",
    "iowa_model = DecisionTreeRegressor(random_state=1)\n",
    "\n",
    "# Fit iowa_model with the training data.\n",
    "iowa_model.fit(train_X,train_y)\n",
    "\n",
    "# Check your answer\n",
    "step_2.check()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "722825a0",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T12:07:28.379199Z",
     "iopub.status.busy": "2025-02-15T12:07:28.378741Z",
     "iopub.status.idle": "2025-02-15T12:07:28.391901Z",
     "shell.execute_reply": "2025-02-15T12:07:28.390714Z"
    },
    "papermill": {
     "duration": 0.022158,
     "end_time": "2025-02-15T12:07:28.394477",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.372319",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 2, \"questionType\": 2, \"questionId\": \"2_FitModelWithTrain\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#3366cc\">Hint:</span> Remember, you fit with training data. You will test with validation data soon"
      ],
      "text/plain": [
       "Hint: Remember, you fit with training data. You will test with validation data soon"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 3, \"questionType\": 2, \"questionId\": \"2_FitModelWithTrain\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc99\">Solution:</span> \n",
       "```python\n",
       "iowa_model = DecisionTreeRegressor(random_state=1)\n",
       "iowa_model.fit(train_X, train_y)\n",
       "```"
      ],
      "text/plain": [
       "Solution: \n",
       "```python\n",
       "iowa_model = DecisionTreeRegressor(random_state=1)\n",
       "iowa_model.fit(train_X, train_y)\n",
       "```"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "step_2.hint()\n",
    "step_2.solution()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bfb9e87d",
   "metadata": {
    "papermill": {
     "duration": 0.005178,
     "end_time": "2025-02-15T12:07:28.405399",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.400221",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "## Step 3: Make Predictions with Validation data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "1af23699",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T12:07:28.418141Z",
     "iopub.status.busy": "2025-02-15T12:07:28.417679Z",
     "iopub.status.idle": "2025-02-15T12:07:28.429581Z",
     "shell.execute_reply": "2025-02-15T12:07:28.428392Z"
    },
    "papermill": {
     "duration": 0.020395,
     "end_time": "2025-02-15T12:07:28.431470",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.411075",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 2, \"questionId\": \"3_ValPreds\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc33\">Correct</span>"
      ],
      "text/plain": [
       "Correct"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Predict with all validation observations\n",
    "val_predictions = iowa_model.predict(val_X)\n",
    "\n",
    "# Check your answer\n",
    "step_3.check()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "0e82f526",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T12:07:28.444984Z",
     "iopub.status.busy": "2025-02-15T12:07:28.444510Z",
     "iopub.status.idle": "2025-02-15T12:07:28.456855Z",
     "shell.execute_reply": "2025-02-15T12:07:28.455665Z"
    },
    "papermill": {
     "duration": 0.021452,
     "end_time": "2025-02-15T12:07:28.458875",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.437423",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 2, \"questionType\": 2, \"questionId\": \"3_ValPreds\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#3366cc\">Hint:</span> Run predict on the right validation data object."
      ],
      "text/plain": [
       "Hint: Run predict on the right validation data object."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 3, \"questionType\": 2, \"questionId\": \"3_ValPreds\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc99\">Solution:</span> \n",
       "```python\n",
       "val_predictions = iowa_model.predict(val_X)\n",
       "```"
      ],
      "text/plain": [
       "Solution: \n",
       "```python\n",
       "val_predictions = iowa_model.predict(val_X)\n",
       "```"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "step_3.hint()\n",
    "step_3.solution()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7ffba4b7",
   "metadata": {
    "papermill": {
     "duration": 0.005624,
     "end_time": "2025-02-15T12:07:28.470845",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.465221",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Inspect your predictions and actual values from validation data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "484f7fad",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T12:07:28.484035Z",
     "iopub.status.busy": "2025-02-15T12:07:28.483580Z",
     "iopub.status.idle": "2025-02-15T12:07:28.500163Z",
     "shell.execute_reply": "2025-02-15T12:07:28.498918Z"
    },
    "papermill": {
     "duration": 0.025532,
     "end_time": "2025-02-15T12:07:28.502267",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.476735",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[186500. 184000. 130000.  92000. 164500.]\n",
      "      LotArea  YearBuilt  1stFlrSF  2ndFlrSF  FullBath  BedroomAbvGr  \\\n",
      "258     12435       2001       963       829         2             3   \n",
      "267      8400       1939      1052       720         2             4   \n",
      "288      9819       1967       900         0         1             3   \n",
      "649      1936       1970       630         0         1             1   \n",
      "1233    12160       1959      1188         0         1             3   \n",
      "\n",
      "      TotRmsAbvGrd  \n",
      "258              7  \n",
      "267              8  \n",
      "288              5  \n",
      "649              3  \n",
      "1233             6  \n"
     ]
    }
   ],
   "source": [
    "# print the top few validation predictions\n",
    "print(iowa_model.predict(val_X.head()))\n",
    "# print the top few actual prices from validation data\n",
    "print(val_X.head())"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bea1d713",
   "metadata": {
    "papermill": {
     "duration": 0.006354,
     "end_time": "2025-02-15T12:07:28.515964",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.509610",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "What do you notice that is different from what you saw with in-sample predictions (which are printed after the top code cell in this page).\n",
    "\n",
    "Do you remember why validation predictions differ from in-sample (or training) predictions? This is an important idea from the last lesson.\n",
    "\n",
    "## Step 4: Calculate the Mean Absolute Error in Validation Data\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "b62f86cc",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T12:07:28.530556Z",
     "iopub.status.busy": "2025-02-15T12:07:28.530150Z",
     "iopub.status.idle": "2025-02-15T12:07:28.542362Z",
     "shell.execute_reply": "2025-02-15T12:07:28.541227Z"
    },
    "papermill": {
     "duration": 0.022193,
     "end_time": "2025-02-15T12:07:28.544484",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.522291",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "29652.931506849316\n"
     ]
    },
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"outcomeType\": 1, \"valueTowardsCompletion\": 0.25, \"interactionType\": 1, \"questionType\": 1, \"questionId\": \"4_MAE\", \"learnToolsVersion\": \"0.3.4\", \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\"}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc33\">Correct</span>"
      ],
      "text/plain": [
       "Correct"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "from sklearn.metrics import mean_absolute_error\n",
    "val_mae = mean_absolute_error(val_y,val_predictions)\n",
    "\n",
    "# uncomment following line to see the validation_mae\n",
    "print(val_mae)\n",
    "\n",
    "# Check your answer\n",
    "step_4.check()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "8396bb6e",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2025-02-15T12:07:28.559672Z",
     "iopub.status.busy": "2025-02-15T12:07:28.559311Z",
     "iopub.status.idle": "2025-02-15T12:07:28.571845Z",
     "shell.execute_reply": "2025-02-15T12:07:28.570709Z"
    },
    "papermill": {
     "duration": 0.022647,
     "end_time": "2025-02-15T12:07:28.573754",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.551107",
     "status": "completed"
    },
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 2, \"questionType\": 1, \"questionId\": \"4_MAE\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#3366cc\">Hint:</span> The order of arguments to mean_absolute_error doesn't matter. Make sure you fit to only the training data in step 2."
      ],
      "text/plain": [
       "Hint: The order of arguments to mean_absolute_error doesn't matter. Make sure you fit to only the training data in step 2."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/javascript": [
       "parent.postMessage({\"jupyterEvent\": \"custom.exercise_interaction\", \"data\": {\"interactionType\": 3, \"questionType\": 1, \"questionId\": \"4_MAE\", \"learnToolsVersion\": \"0.3.4\", \"valueTowardsCompletion\": 0.0, \"failureMessage\": \"\", \"exceptionClass\": \"\", \"trace\": \"\", \"outcomeType\": 4}}, \"*\")"
      ],
      "text/plain": [
       "<IPython.core.display.Javascript object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/markdown": [
       "<span style=\"color:#33cc99\">Solution:</span> \n",
       "```python\n",
       "val_mae = mean_absolute_error(val_y, val_predictions)\n",
       "```"
      ],
      "text/plain": [
       "Solution: \n",
       "```python\n",
       "val_mae = mean_absolute_error(val_y, val_predictions)\n",
       "```"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "step_4.hint()\n",
    "step_4.solution()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "439c259d",
   "metadata": {
    "papermill": {
     "duration": 0.0068,
     "end_time": "2025-02-15T12:07:28.587954",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.581154",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "Is that MAE good?  There isn't a general rule for what values are good that applies across applications. But you'll see how to use (and improve) this number in the next step.\n",
    "\n",
    "# Keep Going\n",
    "\n",
    "You are ready for **[Underfitting and Overfitting](https://www.kaggle.com/dansbecker/underfitting-and-overfitting).**\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "87aa17ae",
   "metadata": {
    "papermill": {
     "duration": 0.006521,
     "end_time": "2025-02-15T12:07:28.601764",
     "exception": false,
     "start_time": "2025-02-15T12:07:28.595243",
     "status": "completed"
    },
    "tags": []
   },
   "source": [
    "---\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "*Have questions or comments? Visit the [course discussion forum](https://www.kaggle.com/learn/intro-to-machine-learning/discussion) to chat with other learners.*"
   ]
  }
 ],
 "metadata": {
  "kaggle": {
   "accelerator": "none",
   "dataSources": [
    {
     "databundleVersionId": 111096,
     "sourceId": 10211,
     "sourceType": "competition"
    },
    {
     "datasetId": 11167,
     "sourceId": 15520,
     "sourceType": "datasetVersion"
    },
    {
     "datasetId": 2709,
     "sourceId": 38454,
     "sourceType": "datasetVersion"
    }
   ],
   "isGpuEnabled": false,
   "isInternetEnabled": false,
   "language": "python",
   "sourceType": "notebook"
  },
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  },
  "papermill": {
   "default_parameters": {},
   "duration": 7.271507,
   "end_time": "2025-02-15T12:07:29.430577",
   "environment_variables": {},
   "exception": null,
   "input_path": "__notebook__.ipynb",
   "output_path": "__notebook__.ipynb",
   "parameters": {},
   "start_time": "2025-02-15T12:07:22.159070",
   "version": "2.6.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
